/*
 * Copyright 2012 Benoît Combe <benoit.combe@gmail.com>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package fr.ipst.spot.entites;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Benoît Combe <benoit.combe@gmail.com>
 */
@Entity
@Table(name = "Evenement", catalog = "SPOT", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Evenement.findAll", query = "SELECT e FROM Evenement e"),
    @NamedQuery(name = "Evenement.findByIdEvenement", query = "SELECT e FROM Evenement e WHERE e.idEvenement = :idEvenement"),
    @NamedQuery(name = "Evenement.findByTitre", query = "SELECT e FROM Evenement e WHERE e.titre = :titre"),
    @NamedQuery(name = "Evenement.findByResume", query = "SELECT e FROM Evenement e WHERE e.resume = :resume"),
    @NamedQuery(name = "Evenement.findByEntrant", query = "SELECT e FROM Evenement e WHERE e.entrant = :entrant")})
public class Evenement extends AbstractSpotEntite implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idEvenement", nullable = false)
    private Integer idEvenement;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "titre", nullable = false, length = 255)
    private String titre;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10000)
    @Column(name = "resume", nullable = false, length = 10000)
    private String resume;
    @Basic(optional = false)
    @NotNull
    @Column(name = "entrant", nullable = false)
    private boolean entrant;
    @JoinTable(name = "EnregistrementAudioEvenement", joinColumns = {
        @JoinColumn(name = "dEvenement", referencedColumnName = "idEvenement", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "idEnregistrementAudio", referencedColumnName = "idEnregistrementAudio", nullable = false)})
    @ManyToMany(fetch = FetchType.EAGER)
    private List<EnregistrementAudio> enregistrementAudioList;
    @ManyToMany(mappedBy = "evenementList", fetch = FetchType.EAGER)
    private List<Email> emailList;
    @ManyToMany(mappedBy = "evenementList", fetch = FetchType.EAGER)
    private List<Pdf> pdfList;
    @JoinColumn(name = "idAgentExterieur", referencedColumnName = "idAgentExterieur")
    @ManyToOne(fetch = FetchType.EAGER)
    private AgentExterieur agentExterieur;
    @JoinColumn(name = "idAuditeur", referencedColumnName = "idAuditeur", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Auditeur auditeur;
    @JoinColumn(name = "idAgentCnam", referencedColumnName = "idAgentCnam", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private AgentCnam agentCnam;
    @Basic(optional = false)
    @NotNull
    @Column(name = "date", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;

    /**
     *
     */
    public Evenement() {
    }

    /**
     *
     * @param idEvenement
     */
    public Evenement(Integer idEvenement) {
        this.idEvenement = idEvenement;
    }

    /**
     *
     * @param idEvenement
     * @param titre
     * @param resume
     * @param entrant
     * @param date
     */
    public Evenement(Integer idEvenement, String titre, String resume, boolean entrant, Date date) {
        this.idEvenement = idEvenement;
        this.titre = titre;
        this.resume = resume;
        this.entrant = entrant;
        this.date = date;
    }

    /**
     *
     * @return
     */
    public Integer getIdEvenement() {
        return idEvenement;
    }

    /**
     *
     * @param idEvenement
     */
    public void setIdEvenement(Integer idEvenement) {
        this.idEvenement = idEvenement;
    }

    /**
     *
     * @return
     */
    public String getTitre() {
        return titre;
    }

    /**
     *
     * @param titre
     */
    public void setTitre(String titre) {
        this.titre = titre;
    }

    /**
     *
     * @return
     */
    public String getResume() {
        return resume;
    }

    /**
     *
     * @param resume
     */
    public void setResume(String resume) {
        this.resume = resume;
    }

    /**
     *
     * @return
     */
    public boolean getEntrant() {
        return entrant;
    }

    /**
     *
     * @param entrant
     */
    public void setEntrant(boolean entrant) {
        this.entrant = entrant;
    }

    /**
     *
     * @return
     */
    @XmlTransient
    public List<EnregistrementAudio> getEnregistrementAudioList() {
        return enregistrementAudioList;
    }

    /**
     *
     * @param enregistrementAudioList
     */
    public void setEnregistrementAudioList(List<EnregistrementAudio> enregistrementAudioList) {
        this.enregistrementAudioList = enregistrementAudioList;
    }

    /**
     *
     * @return
     */
    @XmlTransient
    public List<Email> getEmailList() {
        return emailList;
    }

    /**
     *
     * @param emailList
     */
    public void setEmailList(List<Email> emailList) {
        this.emailList = emailList;
    }

    /**
     *
     * @return
     */
    @XmlTransient
    public List<Pdf> getPdfList() {
        return pdfList;
    }

    /**
     *
     * @param pdfList
     */
    public void setPdfList(List<Pdf> pdfList) {
        this.pdfList = pdfList;
    }

    /**
     *
     * @return
     */
    public AgentExterieur getAgentExterieur() {
        return agentExterieur;
    }

    /**
     *
     * @param agentExterieur
     */
    public void setAgentExterieur(AgentExterieur agentExterieur) {
        this.agentExterieur = agentExterieur;
    }

    /**
     *
     * @return
     */
    public Auditeur getAuditeur() {
        return auditeur;
    }

    /**
     *
     * @param auditeur
     */
    public void setAuditeur(Auditeur auditeur) {
        this.auditeur = auditeur;
    }

    /**
     *
     * @return
     */
    public AgentCnam getAgentCnam() {
        return agentCnam;
    }

    /**
     *
     * @param agentCnam
     */
    public void setAgentCnam(AgentCnam agentCnam) {
        this.agentCnam = agentCnam;
    }

    /**
     *
     * @return
     */
    public Date getDate() {
        return date;
    }

    /**
     *
     * @param date
     */
    public void setDate(Date date) {
        this.date = date;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idEvenement != null ? idEvenement.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Evenement)) {
            return false;
        }
        Evenement other = (Evenement) object;
        if ((this.idEvenement == null && other.idEvenement != null) || (this.idEvenement != null && !this.idEvenement.equals(other.idEvenement))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fr.ipst.spot.entites.Evenement[ idEvenement=" + idEvenement + " ]";
    }

    /**
     *
     * @return
     */
    @Override
    public Integer getId() {
        return this.idEvenement;
    }

    /**
     *
     * @return
     */
    @XmlTransient
    public List<Document> getDocuments() {
        ArrayList<Document> documents = new ArrayList<Document>(this.emailList.size() + this.pdfList.size() + this.enregistrementAudioList.size());
        documents.addAll(this.emailList);
        documents.addAll(this.pdfList);
        documents.addAll(this.enregistrementAudioList);
        return documents;
    }
}
